<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Search result</title>
<script type="text/javascript">
function doSearch(type){
	var keyword = document.getElementById("keyword").value;
	var url = "product?q=" + keyword + "&hl=productName&ft=brandName&wt=jsp";
	if (type == 1) {
		url += "&gp=shop";
	}
	window.location.href = url;
}

function searchBrand(brandName){
	alert(brandName);
	var url = "product?q=" + keyword + "&hl=productName&ft=brandName&wt=jsp";
}
</script>
</head>
<body>
	<div align="center" style="margin-top: 20px;">
		<input type="text" id="keyword" name="keyword" size="25" value="${keyword }">
        <input type="button" value="搜索" onclick="doSearch(0);"/>   
        <input type="button" value="搜店铺" name="searchShop" onclick="doSearch(1);"/>
    </div>
    
   <c:choose>
   	<%-- Grouping search begin --%>
   	<c:when test="${flag_gp==1 }">
   	<div style="margin:50px 200px 0 200px;">
   	<table>
	<c:forEach var="group" items="${sr.groupingResult }" varStatus="status">
    	<tr><td>
    	<div style="display: inline-block;">
    	<img src="${group.hits[0].fieldValues.shopImgUrl }" /> 
    	${group.groupName }
    	</div>
		<c:forEach var="hit" items="${group.hits }" varStatus="status">
			<c:if test="${status.count lt 5}">
				<div style="display: inline-block; margin-left: 30px;">
				<img src="${hit.fieldValues.imgUrl }"/>
				<div style="display: block; width: 200px">
					<c:if test="${not empty ht}"> 
	    				${hit.highlightValues.productName[0]}
	    				<c:if test="${fn:length(hit.highlightValues.productName) == 0}"> 
	    					${hit.fieldValues.productName }
    					</c:if>
    				</c:if>
					<c:if test="${empty ht}"> 
	    				${hit.fieldValues.productName}
    				</c:if>
				</div>
				</div>
    		</c:if>
		</c:forEach>
		</td></tr>
    </c:forEach>
    </table>
    </div>
   	</c:when>
   <%-- Grouping search end --%>
   
   <%-- Normal search begin --%>
   	<c:otherwise>
   	<div style="margin: 20px 0 50px 250px;">
   	<c:if test="${not empty sr.facetResultMap.brandName}"> 品牌：</c:if>
   	 <c:forEach var="nodes" items="${sr.facetResultMap.brandName.nodes }" varStatus="status">
   	 	<%-- <a href="javascript:void(0)" onclick="searchBrand('${nodes.label }')">
    	</a> --%>
    	<span style="margin-left: 10px; display: inline;">${nodes.label }(${nodes.value })</span>
       	
       </c:forEach>
     </div>
       
    <div align="center" style="margin-top: 20px;">
    <table>
    	<c:forEach var="hit" items="${sr.hits }" varStatus="status">
    	<c:if test="${status.count%3 == 1}">
    	<tr style="margin-bottom: 20px">
    	</c:if>
    		<td>
    		<div style="margin-right: 30px">
    		<img src="${hit.fieldValues.imgUrl }" /> 
    		<div style="display: block; width: 200px">
    		<c:if test="${not empty ht}">
    			${hit.highlightValues.productName[0] }
    			<c:if test="${fn:length(hit.highlightValues.productName) == 0}"> 
	    			${hit.fieldValues.productName }
    			</c:if>
    		</c:if>
			<c:if test="${empty ht}"> 
	    		${hit.fieldValues.productName }
    		</c:if>
    		${hit.fieldValues.sale }
    		</div>
    		</div>
    		</td>
    	<c:if test="${status.count%3 == 0}">
    	</tr>
    	</c:if>
    	
       </c:forEach>
       </tr>
    </table>
    </div>
   	</c:otherwise>
   </c:choose>
    <%-- Normal search end --%>
    
</body>
</html>